#!/usr/bin/env python
# coding: utf-8

# In[ ]:





# In[5]:


# encoding:utf-8
import requests 

# client_id 为官网获取的AK， client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=sB01KRSg9dHZgN5AENGGHVZq&client_secret=E5pysADzXT953CQYhRvFXV4ZFQI1FnO6'
response = requests.get(host)
if response:
    print(response.json())


# In[2]:


# encoding:utf-8

import requests
import base64

'''
植物识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant"
# 二进制方式打开图片文件
f = open('./md.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '24.e9dd78bb9dfca941f26feae0ed022cf7.2592000.1659593954.282335-26499637'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())


# In[1]:


# -*- coding: utf-8 -*-
import http.client, urllib
conn = http.client.HTTPSConnection('api.tianapi.com')  #接口域名
params = urllib.parse.urlencode({'key':'a00098f383b4c4943055739960d98d8d','imgurl':'https://tse2-mm.cn.bing.net/th/id/OIP-C.Hvmk9CWLF-YRHIjd9LfsgwHaEo?pid=ImgDet&rs=1'})
headers = {'Content-type':'application/x-www-form-urlencoded'}
conn.request('POST','/scanplant/index',params,headers)
res = conn.getresponse()
data = res.read()
print(data.decode('utf-8'))


# In[ ]:




